﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 打开宝箱窗口
/// </summary>
public class TreasureBoxDialog : MonoBehaviour {

    private GameObject multiple;//多开的GameObject
    private GameObject single; //单开的GameObject

    void Start() {
        multiple = transform.Find("multiple").gameObject;
        single = transform.Find("single").gameObject;
    }
    /// <summary>
    /// 确定按钮
    /// </summary>
    public void OkBtn()
    {
        //当宝箱 多开时
        if (multiple.activeInHierarchy)
        {
            Transform grid = multiple.transform.Find("ScrollRectPanel/Grid");
            for(int i = 0; i < grid.childCount; i++)
            {
                //获取每个武器的对象添加到集合中
                TreasureBoxManager._instance.GetWeaponList().Add(grid.GetChild(i).GetComponent<WeaponIconBag>().weaponInfo);
            }
            //把宝箱的数量设置为0
            TreasureBoxManager._instance.SetBoxNum(0);
            Destroy(gameObject);
        }
        else
        {
            //隐藏页面
            gameObject.SetActive(false);
        }

        //把得到的武器放到武器管理 ,在这里加入适合的代码
        // TreasureBoxManager._instance.GetWeaponList() 得到获得的武器集合

        // to do something
        // to do something  
        // to do something       // to do something
        // to do something       // to do something
        // to do something       // to do something


        //初始化获得的武器集合
        TreasureBoxManager._instance.GetWeaponList().Clear();
    }
    //丢弃武器
    public void TakeAway()
    {
        //单独开启宝箱时
        if (single.activeInHierarchy)
        {
            gameObject.SetActive(false);
            //初始化获得的武器集合
            TreasureBoxManager._instance.GetWeaponList().Clear();
        }
        else
        {
            //多开时 销毁当前选中的武器
            if (TreasureBoxManager._instance.tempGo != null)
            {
                Destroy(TreasureBoxManager._instance.tempGo);
            }
        }

    }



}
